require("../../../utils/function.js");

var e = getApp(), t = require("../../../api.js");

Page({
    data: {
        pageType: null,
        fontImage: null,
        backImage: null,
        idCardPhoto: null,
        idCardPhotoTest: !1,
        driverPhoto: null,
        driverPhotoTest: !1,
        positive: "",
        reverse: "",
        drivers: ""
    },
    upFontloadFile: function(a) {
        if (!this.data.isChange) {
            a.currentTarget.dataset.type;
            var i = this;
            wx.chooseImage({
                success: function(a) {
                    var s = a.tempFilePaths;
                    wx.showLoading({}), wx.uploadFile({
                        url: t.driver.uploadcar,
                        filePath: s[0],
                        name: "file",
                        formData: {
                            access_token: wx.getStorageSync("access_token"),
                            _uniacid: e.siteInfo.uniacid,
                            _acid: e.siteInfo.acid
                        },
                        success: function(e) {
                            if (wx.hideLoading(), 200 == e.statusCode) {
                                var t = JSON.parse(e.data);
                                if (0 == t.code) return void wx.showToast({
                                    title: t.msg,
                                    icon: "none"
                                });
                                i.setData({
                                    positive: t.data
                                }), wx.setStorageSync("positive", t.data);
                            }
                        }
                    });
                }
            });
        }
    },
    upBackloadFile: function(a) {
        if (!this.data.isChange) {
            var i = this;
            a.currentTarget.dataset.type;
            wx.chooseImage({
                success: function(a) {
                    var s = a.tempFilePaths;
                    wx.showLoading({}), wx.uploadFile({
                        url: t.driver.uploadcar,
                        filePath: s[0],
                        name: "file",
                        formData: {
                            user: "test",
                            access_token: wx.getStorageSync("access_token"),
                            _uniacid: e.siteInfo.uniacid,
                            _acid: e.siteInfo.acid
                        },
                        success: function(e) {
                            if (wx.hideLoading(), 200 == e.statusCode) {
                                var t = JSON.parse(e.data);
                                if (0 == t.code) return void wx.showToast({
                                    title: t.msg,
                                    icon: "none"
                                });
                                i.setData({
                                    reverse: t.data
                                }), wx.setStorageSync("reverse", t.data);
                            }
                        }
                    });
                }
            });
        }
    },
    intoPageHandler: function(e) {
        var t = this;
        "true" == this.data.isChange ? wx.showModal({
            title: "提示",
            content: "你已上传图片，请勿重新上传",
            success: function(a) {
                wx.navigateBack({
                    url: e.currentTarget.dataset.skip + "?type=" + t.data.pageType + "&reverse=" + t.data.reverse + "&positive=" + t.data.positive + "&driver=" + t.data.driver,
                    delta: 1
                });
            }
        }) : this.data.positive && this.data.reverse && wx.showToast({
            title: "上传成功",
            success: function() {
                setTimeout(function() {
                    wx.navigateBack({
                        delta: 1
                    });
                }, 1500);
            }
        });
    },
    onLoad: function(t) {
        "true" == t.isChange && this.setData({
            isChange: !0
        }), "driverPhoto" == t.type && "" != wx.getStorageSync("driving_license") && this.setData({
            positive: wx.getStorageSync("driving_license").driverfPhoto,
            reverse: wx.getStorageSync("driving_license").driverPhoto
        }), "idCardPhoto" == t.type && ("" != wx.getStorageSync("id_card_pic") && this.setData({
            positive: wx.getStorageSync("id_card_pic").id_card_pic,
            reverse: wx.getStorageSync("id_card_pic").id_card_fpic
        }), console.log("正面正面", this.data.reverse), console.log("正面正面22", this.data.pageType)), 
        t.uid && e.shareCouponsMessage(t.uid);
    },
    onReady: function() {},
    onShow: function() {
        console.log("onshow");
        var e = wx.getStorageSync("positive") || "", t = wx.getStorageSync("reverse") || "";
        console.log(e, "-----------------"), this.setData({
            driver: wx.getStorageSync("driver_information"),
            positive: e,
            reverse: t
        });
    },
    onShareAppMessage: function() {
        var t = e.shareAppMessage().title, a = e.shareAppMessage().imageUrl, i = e.shareAppMessage().desc, s = e.shareAppMessage().path;
        return console.log(e.shareAppMessage()), {
            title: t,
            imageUrl: a,
            desc: i,
            path: s
        };
    }
});